package com.example.minioservice.minio.config;

import io.minio.MinioClient;
import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationPropertiesScan(basePackageClasses = MinioConfig.MinioProperties.class)
public class MinioConfig {

    @Data
    @ConfigurationProperties(prefix = "minio")
    public static class MinioProperties {
        private String endpoint;
        private String accessKey;
        private String secretKey;
    }

    @SneakyThrows
    @Bean
    public MinioClient minioClient(MinioProperties minioProperties) {
        return MinioClient.builder().endpoint(minioProperties.endpoint)
                .credentials(minioProperties.accessKey, minioProperties.secretKey).build();
    }
}
